package com.easy.service.impl;

import com.easy.bean.Useraddress;
import com.easy.dao.UseraddressDao;
import com.easy.service.IUserAddressService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class UseraddressService implements IUserAddressService {

    @Autowired
    UseraddressDao useraddressDao;


    @Override
    public int add(Useraddress useraddress) {
        return useraddressDao.add(useraddress);
    }

    @Override
    public int edit(Useraddress useraddress) {
        return useraddressDao.edit(useraddress);
    }

    @Override
    public int delete(int useraddressid) {
        return useraddressDao.delete(useraddressid);
    }

    @Override
    public List<Useraddress> getList(Page page, String text,int userid) {
        return useraddressDao.getList(page, text,userid);
    }

    @Override
    public Useraddress getUseraddressById(int useraddressid) {
        return useraddressDao.getUseraddressById(useraddressid);
    }

    @Override
    public int getCount(String text) {
        return useraddressDao.getCount(text);
    }

    @Override
    public Useraddress getUseraddress(Useraddress useraddress) {
        return useraddressDao.getUseraddress(useraddress);
    }

    @Override
    public int cancelDefault(int useraddressid) {
        return useraddressDao.cancelDefault(useraddressid);
    }

    @Override
    public int setDefault(int userid, int useraddressid) {
        // 先取消该用户所有地址的默认状态
        useraddressDao.cancelAllDefault(userid);
        // 再设置指定地址为默认
        return useraddressDao.setDefault(userid, useraddressid);
    }
}
